#!/bin/bash

# 检查是否安装了Python3
if ! command -v python3 &> /dev/null
then
    echo "Python3 is not installed. Please install Python3 first."
    echo "On openKylin, you can install it by running: sudo apt-get install python3"
    exit
fi

# 检查是否安装了p7zip
if ! command -v 7zr &> /dev/null
then
    echo "p7zip is not installed. Please install p7zip first."
    echo "On openKylin, you can install it by running: sudo apt-get install p7zip-full"
    exit
fi

GDVM_DIR="$HOME/.rvgdvm"
mkdir -p $GDVM_DIR
wget -q https://gitee.com/openkylin/godot-riscv/raw/master/rvgdvm -O $GDVM_DIR/rvgdvm
chmod +x $GDVM_DIR/rvgdvm

if [[ ":$PATH:" != *":$GDVM_DIR:"* ]]; then
    echo "export PATH=\"\$PATH:$GDVM_DIR\"" >> $HOME/.bashrc
    echo "export PATH=\"\$PATH:$GDVM_DIR\"" >> $HOME/.zshrc
fi

ln -sf $GDVM_DIR/rvgdvm /usr/local/bin/rvgdvm 2>/dev/null || true

echo "Installation complete. Restart your shell or run: source ~/.bashrc"